﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Churchtoolkit.Utils.Authentication;
using Churchtoolkit.DataAccess.Repositories;
using Churchtoolkit.DataAccess.Entities;
using Churchtoolkit.DataAccess.Common;
using Churchtoolkit.Utils.MVP;
using Churchtoolkit.Web.Shell.Views;

namespace Churchtoolkit.Web.Shell.Presenters
{
    public class EducationWorkPresenters : Presenter<IEducationWorkView>
    {

        private MemberEducationRepository _MemberEducationRepository;
        private MemberJobsRepository _MemberJobsRepository;
        private IAuthentication _authentication;

        public EducationWorkPresenters(MemberEducationRepository MemberEducationRepository, MemberJobsRepository MemberJobsRepository, IAuthentication authentication)
        {
            _MemberEducationRepository = MemberEducationRepository;
            _MemberJobsRepository = MemberJobsRepository;
            _authentication = authentication;
        }

        #region [Education]
        public List<MemberEducation> GetCurrentMemberEducations()
        {
            EntityResult<MemberEducation> Educations;
            Educations = _MemberEducationRepository.Find(items => items.MemberId = _authentication.CurrentLogedInMember.Id);
            List<MemberEducation> currentMemberEducation = new List<MemberEducation>();
            foreach (MemberEducation Education in Educations.Rows)
            {
                currentMemberEducation.Add(new MemberEducation
                {
                    EducationId = Education.EducationId,
                    Name = Education.Name,
                    Type = Education.Type,
                    Year = Education.Year
                });
            }
            return currentMemberEducation;
        }
        public MemberEducation GetCurrentMemberEducation(int EducationId)
        {
            MemberEducation currentMemberEducation = new MemberEducation();
            currentMemberEducation = _MemberEducationRepository.Find(items => items.EducationId = EducationId).Single();
            return currentMemberEducation;
        }
        public void AddNewEducation(MemberEducation CurrentEducation)
        {
            CurrentEducation.MemberId = _authentication.CurrentLogedInMember.Id;
            _MemberEducationRepository.Insert(CurrentEducation);
        }
        public void RemoveEducationInformation(int Id)
        {
            _MemberEducationRepository.Delete(Id);
        }
        public void UpdateEducationInformation(MemberEducation CurrentEducation)
        {
            CurrentEducation.MemberId = _authentication.CurrentLogedInMember.Id;
            _MemberEducationRepository.Update(CurrentEducation);
        }
        #endregion
        #region [Job]
        public List<MemberJobs> GetCurrentMemberJobs()
        {
            EntityResult<MemberJobs> Jobs;
            Jobs = _MemberJobsRepository.Find(items => items.MemberId = _authentication.CurrentLogedInMember.Id);
            List<MemberJobs> currentMemberJobs = new List<MemberJobs>();
            foreach (MemberJobs Job in Jobs.Rows)
            {
                currentMemberJobs.Add(new MemberJobs
                {
                    JobId = Job.JobId,
                    Employeer = Job.Employeer,
                    Position = Job.Position,
                    EmployedFrom = Job.EmployedFrom,
                    EmployedTo = Job.EmployedTo,
                    IsCurrentJob = Job.IsCurrentJob
                });
            }
            return currentMemberJobs;
        }
        public MemberJobs GetCurrentMemberJob(int JobId)
        {
            MemberJobs currentMemberJob = new MemberJobs();
            currentMemberJob = _MemberJobsRepository.Find(items => items.JobId = JobId).Single();
            return currentMemberJob;
        }
        public void AddNewJob(MemberJobs CurrentJob)
        {
            CurrentJob.MemberId = _authentication.CurrentLogedInMember.Id;
            _MemberJobsRepository.Insert(CurrentJob);
        }
        public void RemoveJobInformation(int Id)
        {
            _MemberJobsRepository.Delete(Id);
        }
        public void UpdateJobInformation(MemberJobs CurrentJob)
        {
            CurrentJob.MemberId = _authentication.CurrentLogedInMember.Id;
            _MemberJobsRepository.Update(CurrentJob);
        }
        #endregion
    }
}
